<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        setTimeout(function () { //定时器里是宏任务
            console.log(1)
        })
        new Promise(function (resolve, reject) { //promise里面的是同步任务 立即执行的 .then里面的才是需要等待的异步任务
            console.log(2)
            resolve(3)
        }).then(function (val) { //.then里面是微任务  先执行微任务在执行宏任务
            console.log(val)
        })
        console.log(4)
        // 2 4 3 1  
    </script>
</body>

</html>